/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function TableIncident(myparent, refreshInterval){
    this.parents = myparent;
    this.refreshInterval = refreshInterval;
    this.incidents = new Array();
    this.loadObject = function(json){
        $(this.parents).html("");
        this.incidents = new Array();
        for(var i=0; i < json.length;i++){
            var incident = json[i];
            var jIncident = new Incident("","","","","");
            jIncident.loadJson(incident);
            this.incidents.push(jIncident);
        }
    };
    this.generateTable = function(){
        $(this.parents).html("");
        var table = $("<table>",{
            class : "ui-widget ui-widget-content"
        });
        var header = $("<thead>");
        header.append(this.generateHeader());
        table.append(header);
        var body = $("<tbody>")
        for(var i = 0 ; i <this.incidents.length; i++){
            var incident = this.incidents[i];
            body.append(this.generateIncident(incident));
        }
        table.append(body)
        var footer = $("<tfoot>");
        footer.append(this.generateHeader());
        table.append(footer);
        var button = $("<button>",{
            text : "Ajouter un incident",
            click : function(){
                $("#dialog-form-incident").dialog("open");
            }
        });
        $(this.parents).append(button);
        $(this.parents).append(table);
    }
    this.generateHeader = function(){
        var element = $("<tr>",{
            class : "ui-widget-header"
        });
        var salle = $("<td>",{
            text : "Salle",
        });
        var machine = $("<td>",{
            text : "Machine",
        });
        var date = $("<td>",{
            text : "Date de report",
        });
        var type = $("<td>",{
            text : "Type"
        });
        var dateReso = $("<td>",{
            text : "Date résolution"
        });
        var link = $("<td>",{
            text : "Détails"
        });
        element.append(salle);
        element.append(machine);
        element.append(date);
        element.append(type);
        element.append(dateReso);
        element.append(link);
        return element;
    }
    this.generateIncident = function(incident){
        var element = $("<tr>",{
//            class : "table-incident"
        });
        var salle = $("<td>",{
            text : "TODO",
        });
        var machine = $("<td>",{
            text : incident.getMachine().getIpAddress(),
        });
        var report = $("<td>",{
            text : incident.getDate()
        });
        var type = $("<td>",{
            text : incident.getType()
        });
        var resolve = $("<td>",{
            text : incident.getResolve()
        });
        var link = $("<td>",{
        });
        var a = $("<a>",{
            text: 'Lien',
            title: 'Voir/Modifier',
            href: '#',
            click: function(){ 
                
            }
        });
        link.append(a);
        element.append(salle);
        element.append(machine);
        element.append(report);
        element.append(type);
        element.append(resolve);
        element.append(link);
        
        return element;
    };
}